package com.springboot.controllers;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by francis on 2016/12/24.
 */
@Controller
@RequestMapping("/")
public class HomeController {
    @RequestMapping("home")
    public ModelAndView hi() {
        ModelAndView modelAndView = new ModelAndView();

        modelAndView.addObject("name", "francis");
        return new ModelAndView("home");
    }

    @RequestMapping("home1")
    public String hi1() {
        return "home";
    }

    @RequestMapping(value = "array", method = RequestMethod.GET)
    @ResponseBody
    public String hi2(@RequestParam(value = "ids", required = true, defaultValue = "") long[] ids) {
        if (ids == null || ids.length <= 0) {
            return "空的厣";
        } else {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i <= ids.length - 1; i++) {
                sb.append(String.format("id=%d,", ids[i]));
            }
            return sb.toString();
        }
    }

}
